#include "customeitem.h"
#include <QPainter>


CustomeItem::CustomeItem(QGraphicsItem *parent) :
    QGraphicsItem(parent)
{

}

void CustomeItem::setPixmap(QPixmap *pic)
{
    m_pix = pic;
}

void CustomeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QRectF rect = this->geometry();
    painter->drawPixmap(rect.x() , rect.y() , rect.width() , rect.height() , *m_pix);

}
void CustomeItem::setGeometry(const QRectF &geom)
{
    prepareGeometryChange();
    QGraphicsLayoutItem::setGeometry(geom);
    setPos(geom.topLeft());
}

QSizeF CustomeItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
    switch (which) {
    case Qt::MinimumSize:
    case Qt::PreferredSize:
        // Do not allow a size smaller than the pixmap with two frames around it.
        return m_pix->size() + QSize(12, 12);
    case Qt::MaximumSize:
        return QSizeF(1000,1000);
    default:
        break;
    }
    return constraint;
}

QRectF CustomeItem::boundingRect() const
{
    return QRectF(QPointF(0,0), geometry().size());
}
